import numpy as np
import cv2

img =cv2.imread('C:\\Users\\duanchen\\Pictures\\Saved Pictures\\asuka.jpg')
print(img.shape)
# (458, 458, 3)

# 使用cv2.cvtColor()方法将彩色图片转换为灰度图片
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

print(gray_img.shape)
# (458, 458)

# 将转换后的灰度图片恢复
img2 = cv2.cvtColor(gray_img, cv2.COLOR_GRAY2BGR)
print(img2.shape)
# (458, 458, 3)

cv2.imwrite("asuka2.jpg", img2)